Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ffi: implement our own export macro that always sets up the correct async runtime #4094

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

bnjbvr
Copy link
Member

@bnjbvr bnjbvr commented Oct 8, 2024

The first commit implements new macros:

  • matrix_sdk_ffi_macros::export must be used for all sync functions and impl blocks. It will complain if anything is async (the exported function or any function in the exported impl block).
  • matrix_sdk_ffi_macros::export_async must be used for async functions and impl blocks. Currently, uniffi already complains if the exported item doesn't involve async, so no code had to be added for that.

Screenshot From 2024-10-08 14-59-14
Screenshot From 2024-10-08 14-57-20

The second commit prevents use of the uniffi::export macro by making it into a clippy unauthorized macro, but then the local #[allow()] statement doesn't seem to be taken into account when using the uniffi::export macro internally :( I've opened a thread on the Rust Zulip, to ask if I've missed something by chance or not.

Ways to move forward

  1. only take the first commit
  2. wait for a conclusion over the Clippy side
  3. replace the second commit by a manual check in xtask, using e.g. grep 🤓

Including one that will always warn if used with async functions, and
the other one always setting the tokio runtime if used for async stuff.
@bnjbvr bnjbvr requested a review from a team as a code owner October 8, 2024 14:17
@bnjbvr bnjbvr requested review from stefanceriu, poljar and Hywan and removed request for a team and stefanceriu October 8, 2024 14:17
Copy link
Contributor

@poljar poljar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can wait a bit for the second commit, otherwise I would prefer to merge only the first commit. It's unlikely that anybody will use the wrong macro, people just copy paste things.

Copy link

codecov bot commented Oct 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.67%. Comparing base (4bcb9b7) to head (327a46f).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4094      +/-   ##
==========================================
- Coverage   84.67%   84.67%   -0.01%     
==========================================
  Files         269      269              
  Lines       28753    28753              
==========================================
- Hits        24348    24347       -1     
- Misses       4405     4406       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@Hywan Hywan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the first commit, and I think it's fine, we may not need the second if it's too much work. Well done, thanks!

Comment on lines +2 to +11
description = "Helper macros to write FFI bindings"
edition = "2021"
homepage = "https://github.com/matrix-org/matrix-rust-sdk"
keywords = ["matrix", "chat", "messaging", "ruma"]
license = "Apache-2.0"
name = "matrix-sdk-ffi-macros"
readme = "README.md"
repository = "https://github.com/matrix-org/matrix-rust-sdk"
rust-version = { workspace = true }
version = "0.7.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

authot is missing :-).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't usually set it, or we set it to Damir. Would need to do something more general for all the crates we have :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like setting all to "The Rust Matrix SDK developers" or something like this

@bnjbvr bnjbvr force-pushed the bnjbvr/experiment-with-export-macro branch from 145910c to 327a46f Compare October 8, 2024 14:56
@bnjbvr bnjbvr enabled auto-merge (rebase) October 8, 2024 14:57
@bnjbvr
Copy link
Member Author

bnjbvr commented Oct 8, 2024

Dropped the second commit (since it's a bug in Clippy) and enabled auto-merge. Thanks for the quick reviews!

@bnjbvr bnjbvr merged commit 736aa03 into main Oct 8, 2024
40 checks passed
@bnjbvr bnjbvr deleted the bnjbvr/experiment-with-export-macro branch October 8, 2024 15:11
@@ -0,0 +1,24 @@
[package]
description = "Helper macros to write FFI bindings"
edition = "2021"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2024?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bmarty You can learn what a Rust edition is by reading https://doc.rust-lang.org/edition-guide/editions/index.html :-).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants